package com.xb.health.service.impl;

import com.xb.health.pojo.mgo.MongoUser;
import com.xb.health.repository.MongoUserRepository;
import com.xb.health.service.MongoUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MongoUserServiceImpl implements MongoUserService {

    @Resource
    private MongoUserRepository mongoUserRepository;

    @Override
    public List<MongoUser> queryUsers() {
        return mongoUserRepository.findAll();
    }

    @Override
    public MongoUser queryUsername(String username) {
        return mongoUserRepository.findByUserName(username);
    }

    @Override
    public void insert(MongoUser user) {
        mongoUserRepository.save(user);
    }

    /**
     * 覆盖更新
     * @param user
     */
    @Override
    public void update(MongoUser user) {
        mongoUserRepository.save(user);
    }

    @Override
    public void deleteUser(MongoUser user) {
        mongoUserRepository.deleteById(user.getId());
    }
}
